export default app => {
  const { STRING, INTEGER, DATE, TEXT, DataTypes } = app.Sequelize;

  const organization = app.model.define('organization', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    uuid: { type: STRING(36), unique: true },
    name: STRING(50), // 公司名称
    address: STRING(255), // 公司地址
    code: STRING(50), // 组织机构代码
    fk_type: { type: DataTypes.STRING(36) }, // 公司类型，外键
    filler: STRING(50), // 填写人
    createTime: DATE, // 公司建立时间
    description: TEXT, // 公司简介
    contactTel: STRING(50), // 联系人电话
    contactPerson: STRING(10), // 联系人姓名
    contactEmail: STRING(50), // 联系人email
    updateTime: DATE, // 更新日期
    createdAt: DATE,
    updatedAt: DATE,
  });

  organization.associate = () => {
    app.model.Organization.belongsToMany(app.model.InvestmentDirection, {
      through: app.model.MergeOrganizationInvestment,
      foreignKey: 'organization_id',
      otherKey: 'investment_id',
    });
    app.model.Organization.belongsToMany(app.model.Product, {
      through: app.model.MergeProductOrganization,
      foreignKey: 'organization_id',
      otherKey: 'product_id',
    });
    app.model.Organization.belongsTo(app.model.OrganizationType, {
      foreignKey: 'fk_type',
      targetKey: 'uuid',
    });
  };
  return organization;
};
